import Bean.TimeInDay;
import Bean.Worker;
import Test.Test;
import Utils.TextUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by DespairK on 2016/10/9.
 */
public class Main {

    public static void main(String[] args) {
        String lastName = null;
        boolean dayFirst = false;
        List<Worker> datayuan = new ArrayList<>();
        List<Worker> datagai = new ArrayList<>();
        List<TimeInDay> timeInDayList = new ArrayList<>();
        Test test = new Test();
        datayuan = test.yuan();
        datagai = test.gai();
        TimeInDay timeInDay = new TimeInDay();
        int chidao = 0, zaotui = 0, only = 0, weiFaXian = 0;
        for (int i = 0; i < datayuan.size(); i++) {
            SimpleDateFormat time = new SimpleDateFormat("HH:mm");
            Date date = new Date(datayuan.get(i).getData());
            Date date1 = null;
            try {
                date1 = new Date(datayuan.get(i + 1).getData());
            } catch (Exception e) {
            }
            if (lastName == null) {
                lastName = datayuan.get(i).getName();
                timeInDay.setName(lastName);
                dayFirst = true;
            }
            try {
                if (lastName.equals(datayuan.get(i + 1).getName())) {
                    if (dayFirst) {
                        timeInDay.setDay(String.valueOf(date.getDate()));
                        timeInDay.setMorningTime(time.format(date));
                        dayFirst = false;
                    }
                    if (date.getDate() != date1.getDate()) {
                        timeInDay.setEveningTime(time.format(date));
                        dayFirst = true;
                        timeInDayList.add(timeInDay);
                        timeInDay = new TimeInDay();
                        lastName = datayuan.get(i + 1).getName();
                        timeInDay.setName(lastName);
                    }
                } else {
                    timeInDay.setDay(String.valueOf(date.getDate()));
                    timeInDay.setEveningTime(time.format(date));
                    timeInDayList.add(timeInDay);
                    timeInDay = new TimeInDay();
                    lastName = datayuan.get(i + 1).getName();
                    timeInDay.setName(lastName);
                    dayFirst = true;
                }
            } catch (Exception e) {
                timeInDay.setEveningTime(time.format(date));
                timeInDayList.add(timeInDay);
            }

        }

        String lastName1 = null;

        for (Worker worker : datagai) {
            boolean hasData = false;
            if (lastName1 == null) {
                lastName1 = worker.getName();
            } else if (!lastName1.equals(worker.getName())) {
                System.out.println(lastName1 + " 迟到" + chidao + "  早退" + zaotui + "  只打一次卡" + only + "  未发现打卡数据" + weiFaXian);
                lastName1 = worker.getName();
                chidao = 0;
                zaotui = 0;
                only = 0;
                weiFaXian = 0;
            }
            if ((TextUtils.isEmpty(worker.getMorningHour()) || worker.getMorningHour().equals("0")) && (TextUtils.isEmpty(worker.getAfternoonHour()) || worker.getAfternoonHour().equals("0"))) {
                if (worker.getTeshu() != null && worker.getTeshu().length() > 0) {
                    System.out.println(worker.getName() + "   " + worker.getData() + "  " + worker.getTeshu());
                } else {
                    System.out.println(worker.getName() + "   " + worker.getData() + "  排班表无数据");

                }
            } else {
                if (worker.getTeshu() != null && worker.getTeshu().length() > 0) {
                    System.out.println(worker.getName() + "   " + worker.getData() + "  " + worker.getTeshu());
                } else {
                    for (TimeInDay timeInDay1 : timeInDayList) {
                        if (timeInDay1.getDay().equals(worker.getData()) &&
                                timeInDay1.getName().equals(worker.getName())) {
                            hasData = true;
                            if (timeInDay1.getMorningTime().equals(timeInDay1.getEveningTime())) {
                                System.out.println(worker.getName() + "   " + worker.getData() + "  " + "只打一次卡");
                                only++;
                                break;
                            } else if (timeInDay1.getMorningTime().equals("-2")) {
                                System.out.println(worker.getName() + "   " + worker.getData() + "  只打一次卡");
                                only++;
                                break;
                            }
                            if (worker.getMorningHour().equals("4")) {
                                if (timeInDay1.getMorningTime().compareTo("08:35") < 0) {
                                    System.out.print(worker.getName() + "   " + worker.getData() + "  早晨打卡正常  ");
                                } else {
                                    System.out.print(worker.getName() + "   " + worker.getData() + "  早晨迟到  ");
                                    chidao++;
                                }
                            } else if (worker.getMorningHour().equals("3.5")) {
                                if (timeInDay1.getMorningTime().compareTo("09:05") < 0) {
                                    System.out.print(worker.getName() + "   " + worker.getData() + "  早晨打卡正常  ");
                                } else {
                                    System.out.print(worker.getName() + "   " + worker.getData() + "  早晨迟到  ");
                                    chidao++;
                                }
                            } else if (worker.getMorningHour().equals("4.5")) {
                                if (timeInDay1.getMorningTime().compareTo("08:05") < 0) {
                                    System.out.print(worker.getName() + "   " + worker.getData() + "  早晨打卡正常  ");
                                } else {
                                    System.out.print(worker.getName() + "   " + worker.getData() + "  早晨迟到  ");
                                    chidao++;
                                }
                            } else if (worker.getMorningHour() == null || worker.getMorningHour().equals("0")) {
                                if (timeInDay1.getMorningTime().compareTo("12:05") < 0) {
                                    System.out.print(worker.getName() + "   " + worker.getData() + "  中午打卡正常  ");
                                } else {
                                    System.out.print(worker.getName() + "   " + worker.getData() + "  中午打卡迟到  ");
                                    chidao++;
                                }
                            } else {
                                System.out.print(worker.getName() + "   " + worker.getData() + "  早晨时间手动对比,");
                            }

                            if (worker.getEveningHour() != null && !worker.getEveningHour().equals("0") && worker.getEveningHour().length() > 0) {
                                if (worker.getEveningHour().equals("2")) {
                                    if (timeInDay1.getEveningTime().compareTo("19:00") >= 0) {
                                        System.out.println("晚上打卡正常");
                                    } else {
                                        System.out.println("晚上早退");
                                        zaotui++;
                                    }
                                    break;
                                } else if (worker.getEveningHour().equals("2.5")) {
                                    if (timeInDay1.getEveningTime().compareTo("19:30") >= 0) {
                                        System.out.println("晚上打卡正常");
                                    } else {
                                        System.out.println("晚上早退");
                                        zaotui++;
                                    }
                                    break;
                                } else if (worker.getEveningHour().equals("3")) {
                                    if (timeInDay1.getEveningTime().compareTo("20:00") >= 0) {
                                        System.out.println("晚上打卡正常");
                                    } else {
                                        System.out.println("晚上早退");
                                        zaotui++;
                                    }
                                    break;
                                } else if (worker.getEveningHour().equals("3.5")) {
                                    if (timeInDay1.getEveningTime().compareTo("20:30") >= 0) {
                                        System.out.println("晚上打卡正常");
                                    } else {
                                        System.out.println("晚上早退");
                                        zaotui++;
                                    }
                                    break;
                                } else if (worker.getEveningHour().equals("4")) {
                                    if (timeInDay1.getEveningTime().compareTo("20:00") >= 0) {
                                        System.out.println("晚上打卡正常");
                                    } else {
                                        System.out.println("晚上早退");
                                        zaotui++;
                                    }
                                    break;
                                } else if (worker.getEveningHour().equals("1")) {
                                    if (timeInDay1.getEveningTime().compareTo("18:00") >= 0) {
                                        System.out.println("晚上打卡正常");
                                    } else {
                                        System.out.println("晚上早退");
                                        zaotui++;
                                    }
                                    break;
                                } else if (worker.getEveningHour().equals("1.5")) {
                                    if (timeInDay1.getEveningTime().compareTo("18:30") >= 0) {
                                        System.out.println("晚上打卡正常");
                                    } else {
                                        System.out.println("晚上早退");
                                        zaotui++;
                                    }
                                    break;
                                } else if (worker.getEveningHour().equals("0.5")) {
                                    if (timeInDay1.getEveningTime().compareTo("17:30") >= 0) {
                                        System.out.println("晚上打卡正常");
                                    } else {
                                        System.out.println("晚上早退");
                                        zaotui++;
                                    }
                                    break;
                                } else {
                                    System.out.println("   晚上手动对比");
                                }
                            } else {
                                if (worker.getAfternoonHour().equals("4")) {
                                    if (timeInDay1.getEveningTime().compareTo("16:30") >= 0) {
                                        System.out.println("下午打卡正常");
                                    } else {
                                        System.out.println("下午早退");
                                        zaotui++;
                                    }
                                    break;
                                } else if (worker.getMorningHour().equals("3.5")) {
                                    if (timeInDay1.getEveningTime().compareTo("16:30") >= 0) {
                                        System.out.println("下午打卡正常");
                                    } else {
                                        System.out.println("下午早退");
                                        zaotui++;
                                    }
                                    break;
                                } else {
                                    System.out.println("下午手动对比");
                                }
                            }

                        }
                    }
                    if (!hasData && worker.getMorningHour() != null && worker.getMorningHour().length() > 0) {
                        System.out.println(worker.getName() + "   " + worker.getData() + "   未发现打卡数据");
                        weiFaXian++;
                    }
                }

            }

        }

    }

}
